//
//  FMCollectionViewCell.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FMCollectionViewCell.h"
#import "FMTitleTableViewCell.h"
#import "FMTableViewCell.h"
#import "FMListModel.h"
#import "tListRadioModel.h"

@interface FMCollectionViewCell ()<UITableViewDelegate, UITableViewDataSource, FMTableViewCellDeledate>

@property (nonatomic, strong) UITableView *tableV;

@end

@implementation FMCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.tableV.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height - 90 * HEIGHT);
}

- (void)setArr:(NSMutableArray *)arr
{
    _arr = arr;
    [self.tableV reloadData];
}

- (void)createSubview
{
    self.backgroundColor = [UIColor whiteColor];
    
    self.tableV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.tableV];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return self.arr.count * 2;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (0 == (indexPath.row) % 2) {
            return 50 * HEIGHT;
        } else {
        
            return (SCREEN_WIDTH - 50 * HEIGHT) / 2 + 25 * HEIGHT;
           
        
        }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (0 == (indexPath.row % 2)) {
            static NSString *cellStr = @"cellS";
            UITableViewCell *cellS = [tableView dequeueReusableCellWithIdentifier:cellStr];
            if (nil == cellS) {
                cellS = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
            }
            if (0 != self.arr.count) {
                
                cellS.textLabel.text = [[self.arr objectAtIndex:indexPath.row / 2] cname];
                
                cellS.imageView.image = [UIImage imageNamed:@"audionews_playlist_playing02"];
            }
            
            cellS.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cellS.selectionStyle = UITableViewCellSelectionStyleNone;
            return cellS;
        } else {
            
            static NSString *cellMain = @"cellM";
            FMTableViewCell *cellM = [tableView dequeueReusableCellWithIdentifier:cellMain];
            if (nil == cellM) {
                cellM = [[FMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellMain];
            }
            cellM.arr = [[self.arr objectAtIndex:indexPath.row / 2] tList];
            cellM.delegate = self;
            cellM.index = indexPath.row / 2;
            return cellM;
        }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.delegate returnToListDateilByIndex:indexPath.row / 2];
}

- (void)returnPlayerByRow:(NSInteger)row index:(NSInteger)index
{
    [self.delegate playByRow:row index:index];
}

@end
